package com.gitee.flow.service;

import com.gitee.jmash.core.orm.DtoPageImpl;
import com.gitee.jmash.core.orm.DtoTotal;
import com.gitee.jmash.core.orm.tenant.TenantService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import jmash.flow.protobuf.HiCommentModel;
import jmash.flow.protobuf.HiProcInstModel;
import jmash.flow.protobuf.HiProcinstKey;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.engine.task.Attachment;
import org.flowable.engine.task.Comment;
import org.flowable.identitylink.api.IdentityLink;
import org.flowable.task.api.Task;
import jmash.flow.protobuf.HiProcInstReq;
import jmash.flow.protobuf.ProcDefReq;
import jmash.flow.protobuf.ProcInstReq;
import jmash.flow.protobuf.TaskAttachmentReq;
import jmash.flow.protobuf.TaskDefList;
import jmash.flow.protobuf.TaskIdentityLinkReq;
import jmash.flow.protobuf.TaskModel;
import jmash.flow.protobuf.TaskPage;
import jmash.flow.protobuf.TaskReq;
import org.flowable.variable.api.history.HistoricVariableInstance;

/**
 * Flow服务Read接口.
 *
 * @author <a href="mailto:service@crenjoy.com">crenjoy</a>
 */
public interface FlowRead extends TenantService {

  /** 获取流程定义列表. */
  List<ProcessDefinition> findProcDefList(@NotNull @Valid ProcDefReq req);

  /** 通过Key获取最新版本的流程定义. */
  ProcessDefinition findProcDefByKey(@NotBlank String key);

  /** 通过流程ID获取流程定义. */
  ProcessDefinition findProcDefById(@NotBlank String procDefId);

  /** 获取流程定义图. */
  String findProcDefDiagram(@NotBlank String procDefId) throws FileNotFoundException, IOException;

  /** 流程定义XML. */
  String findProcDefXmlById(@NotBlank String procDefId) throws IOException;
  
  /** 查询运行流程实例. */
  DtoPageImpl<ProcessInstance, DtoTotal> findProcInstPage(@NotNull @Valid ProcInstReq request);
  
  /** 查询历史流程实例. */
  DtoPageImpl<HistoricProcessInstance, DtoTotal> findHiProcInstPage(@NotNull @Valid HiProcInstReq request);
  
  /** 查询任务翻页. */
  DtoPageImpl<Task, DtoTotal> findTaskPage(@NotNull @Valid TaskReq request);
  
  /** 查询任务及实例翻页. */
  TaskPage findTaskModelPage(@NotNull @Valid TaskReq request);
  
  /** 查询任务实例. */
  TaskModel findTaskModelById(@NotNull String taskId);
  
  /** 查询流程实例历史办理记录.*/
  List<HiCommentModel> findHiCommentList(@NotBlank String procInstId);
  
  /** 获取流程实例. */
  ProcessInstance findProcInst(@NotBlank String procInstId);
  
  /** 获取流程实例变量. */
  Map<String,Object> findProcInstVars(@NotBlank String executionId);
  
  /** 获取流程实例定义图. */
  String findProcInstDiagram(@NotBlank String procInstId) throws FileNotFoundException, IOException;
  
  /** 获取允许退回的当前流程历史历史任务. */
  TaskDefList findTaskDefAllowGoback(@NotBlank String taskId);
  
  /** 任务附件列表. */
  List<Attachment> findTaskAttachmentByReq(@NotNull @Valid TaskAttachmentReq req);
  
  /** 任务用户列表. */
  List<IdentityLink> findTaskIdentityLinkByReq(@NotNull @Valid TaskIdentityLinkReq req);

  /** 查询历史流程实例信息. */
  HistoricProcessInstance findHiProcInstById(@NotNull @Valid HiProcinstKey req);

  /** 查询历史流程实例变量. */
  Map<String,Object> findHiProcVars(String procInstId);
}
